package com.example.book.dao.impl;

import com.example.book.dao.UserDao;
import com.example.book.pojo.User;

/**
 * @Description
 * @ClassName UserDaoImpl
 * @Author 山山大魔王
 * @Date 2021/11/10 21:12
 * @Version 1.0
 */
public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public User queryUserByUsername(String username) {
        String sql = "select `id`,`username`,`password`,`email` from t_user where `username`=?";

        User user = queryForOne(sql, User.class, username);
        return user;
    }

    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`email` from t_user where `username`=? and `password`=?";

        User user = queryForOne(sql, User.class, username,password);
        return user;
    }

    @Override
    public int saceUser(User user) {
        String sql = "insert into t_user(`username`,`password`,`email`) values(?,?,?)";
        return update(sql, user.getUsername(), user.getPassword(), user.getEmail());
    }
}
